
// 该文件是为了避免git不提交空文件夹问题放在这里的

import Mock from 'mockjs'
let list = []
for (let i = 0; i < 11; i++) {
  list.push(Mock.mock({ "id": "@increment" }))
}
export default ({ mock }) => {
  if (!mock) return;
  //查询
  Mock.mock('/Admin/list', 'get', (res) => {
    const { pageNumber = 1, pageSize = 10 } = JSON.parse(res.body)

    const pageList = list.filter((item, index) => index < pageSize * pageNumber && index >= pageSize * (pageNumber - 1))
    return {
      "code": "200",
      "data": {
        "pageNumber": Number(pageNumber),
        "pageSize": Number(pageSize),
        "total": list.length,
        "list": pageList
      },
      "message": "成功",
      "success": true
    }
  })
  //增加
  Mock.mock('/Admin/add', 'put', (res) => {
    const data = JSON.parse(res.body)
    list.push(data)
    return {
      "code": "200",
      "message": "成功",
      "success": true
    }
  })
  //修改
  Mock.mock('/Admin/update', 'post', (res) => {
    const data = JSON.parse(res.body)
    list.forEach((item, index) => {
      if (item.id == data.id) {
        list[index] = data
      }
    })
    return {
      "code": "200",
      "message": "成功",
      "success": true
    }
  })
  // 删除
  Mock.mock('/Admin/del', 'delete', (res) => {
    const data = JSON.parse(res.body)
    list.forEach((item, index) => {
      if (item.id == data.id) {
        list.splice(index, 1)
      }
    })
    return {
      "code": "200",
      "message": "成功",
      "success": true
    }
  })
}